package com.leet.tree;

import java.util.ArrayList;
import java.util.List;

public class FindTarget {
    List<Integer> list = new ArrayList<>();
    public boolean findTarget(TreeNode root, int k) {
        helper(root);
        int i = 0, j = list.size()-1;
        while(i < j){
            if(list.get(i) + list.get(j) == k) return true;
            else if(list.get(i) + list.get(j) < k){
                i++;
            }else j--;
        }
        return false;
    }
    void helper(TreeNode root){
        if(root == null) return;
        helper(root.left);
        list.add(root.val);
        helper(root.right);
    }
}
